<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tuijian/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/config/city_config.php");

//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;

	
	cgi::both($g_cgival["tag_id"], "tag_id", "");
	$g_cgival["tag_id"] = intval($g_cgival["tag_id"]);
	
	cgi::both($g_cgival["show_type"], "show_type", "");
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["order"], "order", "");
}


function get_data()
{
	
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "mblog";
	$pcount = $g_show["pcount"] = $g_cgival["pcount"] = 20;
	//登录相关
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	$p = $g_show["p"] = $g_cgival["p"];
	$topic_id = $g_cgival["topic_id"] = $config["current_site_id"];
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
	
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	
	
	$g_show["order"] = $order;
	
	if($config["current_site_id"])
	{
		$current_site_name = $config["current_site_name"];
	}
	
	$g_show["page_keywords"]  = "游戏图片,cosplay图 ,游戏cosplay图片";
	if($current_site_name)$g_show["page_keywords"]  .= ",{$current_site_name},{$current_site_name}职业,{$current_site_name}图片,{$current_site_name}视频,{$current_site_name}组队,{$current_site_name}玩家,一起玩{$current_site_name},玩{$current_site_name},玩{$current_site_name}的人";
	
	$g_show["page_desc"]  = "{$current_site_name}玩家分享的游戏美图,{$current_site_name}玩家聚集地";
	$g_show["page_title"] = "{$current_site_name}图库_{$current_site_name}美图_游戏美图_美女图_游戏图片_cosplay_游戏cosplay";
	
	if($config["site_alias"][$config["current_site_id"]])
	{
		foreach($config["site_alias"][$config["current_site_id"]] as $value)
		{
			$g_show["page_keywords"]  .= "{$value},{$value}攻略,{$value}资讯,{$value}新闻,{$value}视频,{$value}职业";
			$g_show["page_title"] .= "{$value}美图";
		}
	}
	
	//类型1
	$mod_mblog = new mod_mblog();
	$g_show["topic_id"] = $g_cgival["topic_id"];
	$g_show["topic_show_type"] = $config["topic_show_type"];
	
	
	
	$db_mblog_pic_content = new db_mblog_pic_content();
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
	$topic_tag_list = $db_mblog_cron_topic_tag->get_current_tag_list_order_by_count_mblog(1,50,$topic_id);
	
	$list = array();
	
	foreach($topic_tag_list as $key => $value)
	{
		$pic_info = $db_mblog_pic_content->get_mblog_pubu_list_by_topic(1,1,$topic_id,"",$value["id"],1);
		if($pic_info)
		{
			$pic_info[0]["domain_url"] = "http://".$config["domain_url"][$pic_info[0]["topic_id"]];
			if($pic_info[0])
			{
				if($pic_info[0]["from"] ==2)
				{
					$pic_info[0]["pic"] = str_replace("/bmiddle/","/thumb300/",$pic_info[0]["pic"]);
				
				}
				else
				{
					$pic_info[0]["pic"]   = str_replace("/460/","/460",$pic_info[0]["pic"]);
				}
				
				$list[] = $pic_info[0];
			}
			
		}
	
	}
	
	$g_show["list"] = $list;
	
	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;
	
	$db_mblog_meinv_topic = new db_mblog_meinv_topic();
	$db_mblog_meinv_content = new db_mblog_meinv_content();
	$meinv_topic_list = $db_mblog_meinv_topic->get_mblog_meinv_topic_list_order_by_like(1,5);
	
	$meinv_tuijian = array();
	foreach($meinv_topic_list as $key => $value)
	{
		$pic_info =  $db_mblog_meinv_content->get_mblog_pubu_list_by_topic(1,1,$value["id"]);
		
		if($pic_info[0])
		{
			$pic_info[0]["pic"] = str_replace("/bmiddle/","/thumb300/",$pic_info[0]["pic"]);
			$meinv_tuijian[] = $pic_info[0];
		}
		
	}
	$g_show["meinv_tuijian"] = $meinv_tuijian;
	
	
	$db_mblog_video_content = new db_mblog_video_content();
	if($topic_id)
	{
		$video_tuijian = $db_mblog_video_content->get_mblog_video_content_have_pic(1,2,$topic_id);
	}
	else
	{
		//视频需要重新处理
		$video_tuijian = array();
		foreach($config["site"] as $key => $value)
		{
			if(!$value)continue;
			$video_tuijian_item = $db_mblog_video_content->get_mblog_video_content_have_pic(1,1,$value);
			if($video_tuijian_item[0])$video_tuijian[] = $video_tuijian_item[0];
		}
		
		//头部导航
		
		$sites_array = array();
		foreach($config["site_name"] as $key => $value)
		{
			
			if($key)
			{
				$sites["site_name"] =  $value;
				$sites["domain_url"] = "http://". $config["domain_url"][$key];
			}
			else
			{
				continue;
			}
			$sites_array[] = $sites;
		}
		$g_show["sites_array"] = $sites_array;
		
	}
	
	foreach($video_tuijian as $key => $value)
	{
		$video_tuijian[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
		$video_tuijian[$key]["pic"] = str_replace("/bmiddle/","/thumb300/",$video_tuijian[$key]["pic"]);
	}
	$g_show["video_tuijian"] = $video_tuijian;
	
	$g_show["main_domain"] = "http://".$config["main_domain"];
	
	//推荐达人
	$site_id = $config["current_site_id"];
	$start_year = "2013";
	$get_weeks = ceil((time()-strtotime("$start_year-01-01"))/(86400*7));
	$db_tuijian_daren = new db_tuijian_daren();
	$tuijian_daren_list = $db_tuijian_daren->get_top_list_by_order(1,2,$get_weeks,$site_id);
	foreach($tuijian_daren_list as $key =>$value)
	{
		$tuijian_daren_list[$key]["detail_info"] = unserialize($tuijian_daren_list[$key]["detail_info"]);
		$tuijian_daren_list[$key]["detail_info"]["main_topic"] = $config['site_name'][$tuijian_daren_list[$key]["detail_info"]["main_topic_id"]];
		$tuijian_daren_list[$key]["detail_info"]["head_url"]= str_replace("/50/","/180/",$tuijian_daren_list[$key]["detail_info"]["head_url"] );
		
		$tuijian_daren_list[$key]["detail_info"]["province_name"] = $config['province'][$tuijian_daren_list[$key]["detail_info"]["province"]]["name"];
		$tuijian_daren_list[$key]["detail_info"]["city_name"] = $config['city'][$tuijian_daren_list[$key]["detail_info"]["province"]][$tuijian_daren_list[$key]["detail_info"]["city"]];
		$old = date("Y")-$tuijian_daren_list[$key]["detail_info"]["birthyear"];
		if($old < 200){
		$tuijian_daren_list[$key]["detail_info"]["old"] =$old  ;
		}
		
	}
	$g_show["tuijian_daren_list"] = $tuijian_daren_list;
	
	
	
	
	$db_mblog_want_content = new db_mblog_want_content();
	$new_want_list = $db_mblog_want_content->get_mblog_want_list_by_topic(1,5,$topic_id);
	foreach($new_want_list as $key => $value)
	{
		$new_want_list[$key]["content_short"] = string_utf8::substr_utf8_cn_v2($new_want_list[$key]["content"],36);
		$new_want_list[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
		$new_want_list[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
	}
		
	$g_show["new_want_list"] = $new_want_list;
	
	
	
	
		//右侧推荐
		$db_gonglue = new db_gonglue();
		$gonglue_list1 = $db_gonglue->get_list_order_by_time(1,6,0,$config["current_site_id"]);
		$gonglue_list2 = $db_gonglue->get_list_order_by_time(1,6,1,$config["current_site_id"]);
		foreach($gonglue_list1 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list1[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list1[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list1[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list1[$key]["title"],36);
		}
		
		foreach($gonglue_list2 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list2[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list2[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list2[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list2[$key]["title"],36);
		}
			
		
		$g_show["gonglue_list1"] = $gonglue_list1;
		$g_show["gonglue_list2"] = $gonglue_list2;
		
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$meinv_tuijian_list = $db_mblog_meinv_content->get_mblog_meinv_list_by_tuijian(1,9);
		foreach($meinv_tuijian_list as $key => $value)
		{
			$meinv_tuijian_list[$key]["pic_small"]  = str_replace("/bmiddle/","/thumb150/",$meinv_tuijian_list[$key]["pic"]);
		}
		
		$g_show["meinv_tuijian_list"] = $meinv_tuijian_list;
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("index.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

